﻿using System;
using System.Collections.Generic;
using System.Text;

namespace 设计模式01
{
    /// <summary>
    /// 指挥者
    /// </summary>
    public class Director
    {
        public void Construct(Builder builder)
        {
            builder.BuildPartCPU();

            builder.BuildPartMainBoard();

        }
    }

    /// <summary>
    /// 建造者模式
    /// </summary>
    public abstract class Builder
    {
        public abstract void BuildPartCPU();

        public abstract void BuildPartMainBoard();

        public abstract Computer GetComputer();

    }

    public class Computer
    {
        private IList<string> parts = new List<string>();

        public void Add(string part)
        {
            parts.Add(part);
        }

        public void Show()
        {
            Console.WriteLine("电脑开始在组装。。。。");
            foreach (string part in parts)
            {
                Console.WriteLine($"组件{part}已经装好");
            }

            Console.WriteLine("电脑组装好了");
        }
    }

    public class ConcreteBuilder1 : Builder
    {
        private Computer computer = new Computer();
        public override void BuildPartCPU()
        {
            computer.Add("CPU1");
        }

        public override void BuildPartMainBoard()
        {
            computer.Add("Main board1");
        }

        public override Computer GetComputer()
        {
            return computer;
        }
    }

    class ConcreteBuilder2:Builder
    {
        private Computer computer = new Computer();
        public override void BuildPartCPU()
        {
            computer.Add("CPU2");
        }

        public override void BuildPartMainBoard()
        {
            computer.Add("Main board2");
        }

        public override Computer GetComputer()
        {
            return computer;
        }
    }

}
